<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>编辑章节</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/layer/layer.js"></script>
</head>
<style>
    .newadd {
        padding: 10px 0;
        display: block;
        text-align: left;
    }

    .newadd label .adtitle {
        display: inline-block;
        width: 6rem;
        text-align: right;
        padding-right: 2%;
    }

    .newadd input {
        padding: 0 10px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .newadd select {
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .button button {
        color: #fff;
        padding: 5px 10px;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        border-radius: 3px;
    }

    .button button a {
        color: #fff;
    }
</style>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    {% include "admin/top.html" %}
    {% include "admin/left.html" %}
    <div class="layui-body">
        <div id="box" class="fl" style="width: 100%">
            <div class="content">
                <h3>编辑课程</h3>
                <div class="newadd">
                    <label for="">
                        <span class="adtitle">教师</span>
                        <select style="background-color: #EEEEEE;" disabled id="tc">
                            <option value="0">{{ res.nickName | default('', true) }}</option>
                        </select>
                    </label>

                    <label for="">
                        <span class="adtitle">主题</span>
                        <select style="background-color: #EEEEEE;" disabled id="km">
                            <option>{{ res.typeName | default('', true) }}</option>

                        </select>
                    </label>

                    <label for="">
                        <span class="adtitle">分类</span>
                        <select style="background-color: #EEEEEE;" disabled id="ctype">
                            <option>{{ res.tname | default('', true) }}</option>
                        </select>
                    </label>

                    <label>
                        <span class="adtitle">课程名称</span>
                        <select style="background-color: #EEEEEE;" disabled id="ctype">
                            <option>{{ res.courseName | default('', true) }}</option>
                        </select>
                    </label>
                    <label>
                        <span class="adtitle">章节名称</span>
                        <input type="text" id="cname" class="create" value="{{ res.chapterName | default('', true) }}">
                    </label>
                    <label>
                        <span class="adtitle">上传文件</span>
                        {% if res.url %}
                        <input type="text" value="{{ url }}{{ res.url }}" id="url" />
                        {% endif %}
                        <input type="file" name="file" id="xdaTanFileImg">
                    </label>

                    <label class="button" style="margin-left: 8rem;">
                        <button id="btn" class="subbtn">提交</button>
                        <button class="subbtn">
                            <a href="javascript:window.history.go(-1)">返回</a>
                        </button>
                    </label>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    $("#btn").click(function () {
        var cname = $('#cname').val();
        var cid = "{{ res.id }}";
        if (cname == ''){
            layer.msg("章节名称不能为空");
            return false;
        }
        layer.load(9);
        $.ajaxFileUpload({
            url: "/admin/chapter_detail_post",
            type: "POST",
            dataType: 'json',
            data: {
                "cname":cname,
                "cid":cid
            },
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'xdaTanFileImg', //文件上传域的ID
            success: function (msg) {
                if (msg.status == 1) {
                    layer.closeAll('loading');
                    layer.msg("更新成功", {time: 2000}, function () {
                        location.href = window.history.go(-1);
                    })
                } else {
                    layer.closeAll('loading');
                    layer.msg("操作失败");
                }
            }
        })
    })
</script>



